/*
 * @Descripttion: Icon组件
 * @version:
 * @Author: lhl
 * @Date: 2024-11-18 18:50:02
 * @LastEditors: lhl
 * @LastEditTime: 2024-11-18 18:50:22
 */
import React from 'react';
import * as AntdIcons from '@ant-design/icons';
import { createFromIconfontCN } from '@ant-design/icons';

// 如果使用iconfont，可以在这里配置
const IconFont = createFromIconfontCN({
  scriptUrl: '//at.alicdn.com/t/font_xxxx_xxxx.js', // 替换为你的iconfont脚本地址
});

interface IconProps {
  name: string;
  className?: string;
  style?: React.CSSProperties;
}

const Icon: React.FC<IconProps> = ({ name, className, style }) => {
  // 处理Ant Design内置图标
  if (name in AntdIcons) {
    const AntIcon = (AntdIcons as any)[name];
    return <AntIcon className={className} style={style} />;
  }

  // 处理iconfont图标
  if (name.startsWith('icon-')) {
    return <IconFont type={name} className={className} style={style} />;
  }

  // 如果找不到对应的图标，返回null或默认图标
  console.warn(`Icon "${name}" not found`);
  return null;
};

export default Icon;
